<section class="title">
<?php if ($this->method == 'create'): ?>
	<?php $readonly = '';?>
	<h4><?php echo lang('escort_invoice_add_title'); ?></h4>
<?php else: ?>
	<?php $readonly = 'readonly="readonly"';?>
	<h4><?php echo lang('escort_invoice_edit_title'); ?></h4><div class="export-button"><?php echo anchor(site_url().'admin/be_invoice/export_to_pdf/'.$invoice->id, lang('escort_invoice_export_to_pdf_label'), 'class="btn orange" id="invoice_export"')?></div>
<?php endif; ?>
</section>

<section class="item">
	
<?php echo form_open(uri_string(), 'class="crud"'); ?>
<div class="form_inputs" id="news-form">

	<fieldset>
	
		<ul>
			<li class="even">
				<label for="created_time"><?php echo lang('escort_invoice_date_label'); ?> <span>*</span></label>
				<div class="input">
				<?php
				if($invoice->created_time){
				?>
				<?php echo form_input('created_time',format_date($invoice->created_time), 'id="created_time" '); ?>
				<?php
				}else{ 
				?>
				<?php echo form_input('created_time','', 'id="created_time" '); ?>
				<?php
				} 
				?>
				</div>				
			</li>
			<li class="odd">
				<label for="expire_date"><?php echo lang('escort_invoice_expiration_date_label'); ?></label>
				<div class="input">

				<?php
				if($invoice->expire_date){
				?>			
				<?php echo form_input('expire_date',  format_date($invoice->expire_date), 'id="expire_date"') ?>
				<?php
				}else{ 
				?>
				<?php echo form_input('expire_date','', 'id="expire_date" '); ?>		<?php
				} 
				?>
				</div>
			</li>
			<li class="even">
				<label for="status"><?php echo lang('escort_invoice_paid_label'); ?> <span>*</span></label>
				<div class="input">
				<?php echo form_dropdown('status', $statusList, $invoice->status)?>
				<?php
				if($invoice->paid_date){
				?>
				<?php echo form_input('paid_date',format_date($invoice->paid_date), 'id="paid_date" '); ?>
				<?php
				}else{ 
				?>
				<?php echo form_input('paid_date','', 'id="paid_date" '); ?>
				<?php
				} 
				?>
				</div>				
			</li>
			<li class="odd">
				<label><?php echo lang('escort_invoice_lines_label')?></label>
				<table id="invoice-lines">
					<thead>
						<tr>
							<th><?php echo lang('escort_invoice_ref_label'); ?></th>
							<th class="collapse"><?php echo lang('escort_invoice_description_label'); ?></th>
							<th class="collapse"><?php echo lang('escort_invoice_quantity_label'); ?></th>
							<th class="collapse"><?php echo lang('escort_invoice_price_label'); ?></th>
							<th class="collapse"><?php echo lang('escort_invoice_tax_label'); ?></th>
							<th class="collapse"><?php echo lang('escort_invoice_subtotal_label'); ?></th>
							<th></th>
						</tr>
					</thead>
					<tbody>
					<?php
					if($invoiceLines){
						foreach ($invoiceLines as $line){
					?>
						<tr>
							<td><?php echo $line->product_ref?></td>
							<td><?php echo $line->description ?></td>
							<td><?php echo $line->quantity?></td>
							<td><?php echo round($line->price, 2)?></td>
							<td><?php echo $line->tax?></td>
							<td><?php echo $line->quantity*$line->price*(100 + $line->tax)/100?></td>
							<td><a href="#" class="delete-line" id="<?php echo $line->product_ref?>"><?php echo lang('escort_invoice_delete_label')?></a></td>
							<input type="hidden" name="product_ref[<?php echo $line->product_ref?>]" value="<?php echo $line->product_ref?>" />
							<input type="hidden" name="price[<?php echo $line->product_ref?>]" value="<?php echo $line->price?>" />
							<input type="hidden" name="quantity[<?php echo $line->product_ref?>]" value="<?php echo $line->quantity?>" />
							<input type="hidden" name="tax[<?php echo $line->product_ref?>]" value="<?php echo $line->tax?>" />
							<input type="hidden" name="line_description[<?php echo $line->product_ref?>]" value="<?php echo $line->description?>" />
							<input type="hidden" name="type[<?php echo $line->product_ref?>]" value="<?php echo $line->type?>" />
						</tr>
					<?php
						}
					} 
					?>
					</tbody>
				</table>
			</li>
			<li class="even">
				<?php echo anchor('#', lang('escort_invoice_manual_add_line_label'), 'class="btn orange" id="manual_add_line"')?>
				<?php echo anchor('#', lang('escort_invoice_fetch_from_product_label'), 'class="btn orange" id="fetch_from_product"')?>
			</li>
			<li class="even">
				<label for="company"><?php echo lang('escort_invoice_company_label'); ?></label>
				<div class="input">
					<?php echo form_input('company', $invoice->company)?>
				</div>
			</li>
			<li class="even">
				<label for="company"><?php echo lang('escort_invoice_description_label'); ?></label>
				<div class="input">
					<?php echo form_textarea('description', $invoice->description)?>
				</div>
			</li>
		</ul>
	</fieldset>
</div>
<div class="buttons float-right padding-top">
<?php $this->load->view('admin/partials/buttons', array('buttons' => array('save', 'save_exit', 'cancel'))); ?>
</div>
<?php echo form_close(); ?>
</section>
<div id="basic-modal-content">
	<div class="popup-body add-new-line-popup">
		<section class="title">
			<h4><?php echo lang('escort_invoice_add_new_line_label')?></h4>
		</section>
		<form id="add-new-line-form" action="">
			<input type="hidden" name="thread_id" id="thread_id" value="" />
			<section class="item">			
				<div class="form_inputs">
					<fieldset>
						<ul>
							<li class="even">
								<label for="product_ref"><?php echo lang('escort_invoice_ref_label')?><span>*</span></label>
								<div class="input">
									<?php echo form_input('product_ref', '','id="product_ref"'); ?>
								</div>
							</li>
							<li class="even">
								<label for="price"><?php echo lang('escort_invoice_price_label')?><span>*</span></label>
								<div class="input">
									<?php echo form_input('price', '','id="price"'); ?>
								</div>
							</li>
							<li class="even">
								<label for="quantity"><?php echo lang('escort_invoice_quantity_label')?><span>*</span></label>
								<div class="input">
									<?php echo form_input('quantity', '','id="quantity"'); ?>
								</div>
							</li>
							<li class="even">
								<label for="tax"><?php echo lang('escort_invoice_tax_label')?><span>*</span></label>
								<div class="input">
									<?php echo form_input('tax', '','id="tax"'); ?>
								</div>
							</li>
							<li class="description">
								<label for="description"><?php echo lang('escort_invoice_description_label')?><span>*</span></label>
								<div class="input">
									<?php //echo form_textarea('description', '','id="description"'); ?>
									<?php
									echo form_textarea(array(
										'name'	=> 'description',
										'value'	=> '',
										'id'	=> 'description',
										'rows'	=> '3',
										'cols'	=> '20'
									));
									?>
								</div>
							</li>
						</ul>
					</fieldset>
				</div>
				<div>
					<?php echo form_button(array('id'=>'save-new-line', 'name'=>'add', 'class'=>'btn blue', 'value'=>lang('escort_invoice_save_label'), 'content'=>lang('escort_invoice_save_label')))?>
					<?php echo form_button(array('id'=>'cancel-new-line', 'name'=>'add', 'class'=>'btn blue modalCloseImg simplemodal-close', 'value'=>lang('escort_invoice_cancel_label'), 'content'=>lang('escort_invoice_cancel_label')))?>
				</div>
			</section>
		</form>
	</div>
</div>
<div id="basic-modal-content-product">
	<div class="popup-body add-new-line-popup">
		<section class="title">
			<h4><?php echo lang('escort_invoice_add_new_line_label')?></h4>
		</section>
		<form id="fetch-line-form" action="">
			<input type="hidden" name="thread_id" id="thread_id" value="" />
			<section class="item">			
				<div class="form_inputs">
					<fieldset>
						<ul>
							<li class="even">
								<label for="product_ref"><?php echo lang('escort_invoice_ref_label')?><span>*</span></label>
								<div class="input">
									<?php echo form_dropdown('product_ref', array('0' => lang('escort_invoice_select_product_label')) + $productList, '', 'id="product_ref"'); ?>
								</div>
							</li>
							<li class="even">
								<label for="price"><?php echo lang('escort_invoice_price_label')?><span>*</span></label>
								<div class="input">
									<?php echo form_input('price', '','id="price" readonly="readonly"'); ?>
								</div>
							</li>
							<li class="even">
								<label for="quantity"><?php echo lang('escort_invoice_quantity_label')?><span>*</span></label>
								<div class="input">
									<?php echo form_input('quantity', '','id="quantity"'); ?>
								</div>
							</li>
							<li class="even">
								<label for="tax"><?php echo lang('escort_invoice_tax_label')?><span>*</span></label>
								<div class="input">
									<?php echo form_input('tax', '','id="tax"'); ?>
								</div>
							</li>
							<li class="description">
								<label for="description"><?php echo lang('escort_invoice_description_label')?><span>*</span></label>
								<div class="input">
									<?php //echo form_textarea('description', '','id="description"'); ?>
									<?php
									echo form_textarea(array(
										'name'	=> 'description',
										'value'	=> '',
										'id'	=> 'description',
										'rows'	=> '5',
										'cols'	=> '20',
										'readonly' => 'readonly'
									));
									?>
								</div>
							</li>
						</ul>
					</fieldset>
				</div>
				<div>
					<?php echo form_button(array('id'=>'save-new-product', 'name'=>'add', 'class'=>'btn blue', 'value'=>lang('escort_invoice_save_label'), 'content'=>lang('escort_invoice_save_label')))?>
					<?php echo form_button(array('id'=>'cancel-new-product', 'name'=>'add', 'class'=>'btn blue modalCloseImg simplemodal-close', 'value'=>lang('escort_invoice_cancel_label'), 'content'=>lang('escort_invoice_cancel_label')))?>
				</div>
			</section>
		</form>
	</div>
</div>